<?php

/*****************************************************************************
 * 
 *  Copyright 2009 Sylvain Dudoit (contact : sylvain.dudoit at gmail.com)
 *  
 *  This file is part of Poupitchi.
 *
 *  Poupitchi is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  Poupitchi is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with Poupitchi.  If not, see <http://www.gnu.org/licenses/>.
 *
 *****************************************************************************/

///////////////////////////////////////////////////////////////////////////////
// Define data location

$P_DATA = "data/";
$P_REQROOT = "http://".$_SERVER['HTTP_HOST']."/";
$P_REQURI = $P_REQROOT.substr($_SERVER['REQUEST_URI'], 0, -7);

///////////////////////////////////////////////////////////////////////////////
// Include dependencies

require_once($P_DATA."config.php");
require_once("library/utils.php");
require_once("library/modules/messages/db.".P_DB.".php");

///////////////////////////////////////////////////////////////////////////////
// RSS generation

header("Content-type: text/xml");
echo '<?xml version="1.0" encoding="utf-8"?>'.PHP_EOL;
echo '<rss version="2.0"
					xmlns:content="http://purl.org/rss/1.0/modules/content/"
					xmlns:wfw="http://wellformedweb.org/CommentAPI/">'.PHP_EOL;
echo '<channel>'.PHP_EOL;
echo '  <title>'.P_TITLE.'</title>'.PHP_EOL;
echo '  <link>'.$P_REQURI.'</link>'.PHP_EOL;
$messages = getMessages(P_NB_MESSAGES);
foreach($messages as $message) {
	echo '<item>'.PHP_EOL;
	echo '  <title>'.ucfirst($message['login']).' : '.$message['title'].'</title>'.PHP_EOL;
	echo '  <link>'.$P_REQURI.'</link>'.PHP_EOL;
	echo '  <pubDate>'.date("D, d M Y H:i:s O", $message['date']).'</pubDate>'.PHP_EOL;
	echo '</item>'.PHP_EOL;
}
echo '</channel>'.PHP_EOL;
echo '</rss>'.PHP_EOL;
?>

